package com.ljx.itbbs.server.user.controller;

import com.ljx.itbbs.common.domain.vo.resp.ApiResult;
import com.ljx.itbbs.server.user.domain.vo.req.LoginBody;
import com.ljx.itbbs.server.user.domain.vo.req.RegisterBody;
import com.ljx.itbbs.server.user.domain.vo.resp.UserResp;
import com.ljx.itbbs.server.user.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 登录接口
 * @Author LiJunXi
 * @Date 2024-03-01 16:36
 */
@Api(tags = "认证接口")
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public ApiResult<String> login(@Valid @RequestBody LoginBody loginBody){
        String token = authService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid(), loginBody.getCheckCodeType());

        return ApiResult.success(token);
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public ApiResult<Void> register(@Valid @RequestBody RegisterBody registerBody){
        authService.registerBody(registerBody);

        return ApiResult.success();
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public ApiResult<UserResp> getUserInfo(){

        return ApiResult.success(authService.getUserInfo());
    }

}
